package com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bean.SeatLog;
import com.dao.SeatLogDao;
import com.service.SeatLogService;
import com.utils.Query;
import com.utils.QueryUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class SeatLogServiceImpl extends ServiceImpl<SeatLogDao, SeatLog> implements SeatLogService {

    @Override
    public IPage<SeatLog> queryByPage(Query query) {
        QueryUtils<SeatLog> seatLogQueryUtils = new QueryUtils<>();
        LambdaQueryWrapper<SeatLog> seatLogLambdaQueryWrapper = new LambdaQueryWrapper<>();
        SeatLog queryParams = query.getQueryParams();
        if (queryParams != null) {
            if (StringUtils.isNotEmpty(queryParams.getSeatName())) {
                seatLogLambdaQueryWrapper = seatLogLambdaQueryWrapper.eq(SeatLog::getSeatName, queryParams.getSeatName().trim());
            }
            if (StringUtils.isNotEmpty(queryParams.getUserName())) {
                seatLogLambdaQueryWrapper = seatLogLambdaQueryWrapper.eq(SeatLog::getUserName, queryParams.getUserName().trim());
            }
            if (StringUtils.isNotEmpty(queryParams.getIp())) {
                seatLogLambdaQueryWrapper = seatLogLambdaQueryWrapper.eq(SeatLog::getIp, queryParams.getIp().trim());
            }
            if (queryParams.getBeginTime() != null) {
                seatLogLambdaQueryWrapper = seatLogLambdaQueryWrapper.ge(SeatLog::getBeginTime, queryParams.getBeginTime());
            }
            if (queryParams.getEndTime() != null) {
                seatLogLambdaQueryWrapper = seatLogLambdaQueryWrapper.le(SeatLog::getEndTime, queryParams.getEndTime());
            }
        }
        return this.page(seatLogQueryUtils.getPage(query), seatLogLambdaQueryWrapper);
    }
}

